<?php

namespace app\agent\controller;

use app\common\service\AddrService;
use app\agent\service\WkOrderService;
use app\common\validate\WkOrderValidate;

/**
 * 订单管理
 * @module     订单管理
 * @controller 订单
 */
class WkOrderController extends BaseController
{
    private $wkOrder = null;

    private $validate = null;

    private $addr = null;

    public function __construct()
    {
        parent::__construct();

        $this->wkOrder = new WkOrderService();

        $this->validate = new WkOrderValidate();

        $this->addr = new AddrService();
    }

    /**
     * @action 订单列表
     */
    public function page()
    {
        $request = input('param.');

        $data = $this->wkOrder->getViewPage($request);

        $this->assign('request', $request);

        $this->assign('data', $data);

        return $this->fetch('page');
    }

    /**
     * @action 订单收益
     */
    public function ProfitPage()
    {
        $request              = input('param.');
        $request['type']      = session('type');
        $request['addr_code'] = session('addr_code');

        $data = $this->wkOrder->getAgentProfit($request);

        //获取下级下拉列表
        $addr[$this->type[$request['type']+1]] = $this->addr->getAddrByPcode($request['addr_code']);

        //下级下拉列表选择了则返回下下级下拉列表
        if( empty($request['city']) === false )
        {
            $addr['county'] = $this->addr->getAddrByPcode($request['city']);
        }

        $this->assign('request', $request);
        $this->assign('addr', $addr);
        $this->assign('data', $data);

        return $this->fetch();
    }


    /**
     * @action 订单详情
     */
    public function detail()
    {
        $request = input('param.');

        $data = $this->wkOrder->getViewDetail($request);

        $this->assign('data', $data);

        return $this->fetch();
    }

    /**
     * @action 商家订单明细
     */
    public function sellerOrder()
    {
        $request = input('param.');

        //验证
        if( $this->validate->scene('sellerOrder')->check($request) === false )
        {
            $this->failure($this->validate->getError());
        }

        //获取数据
        $data = $this->wkOrder->sellerOrder($request);

        $this->assign('data', $data);

        return $this->fetch('detail');
    }

}